import java.util.logging.Logger;
import org.rsbot.script.methods.Calculations;
import org.rsbot.script.methods.Game;
import org.rsbot.script.methods.Interfaces;
import org.rsbot.script.methods.Keyboard;
import org.rsbot.script.methods.Players;
import org.rsbot.script.methods.Skills;
import org.rsbot.script.wrappers.RSComponent;
import org.rsbot.script.wrappers.RSInterface;
import org.rsbot.script.wrappers.RSPlayer;

class WhiteBearAIOMagic$ChatResponder extends Thread
{
  long lastSaidHi = System.currentTimeMillis() - 110000L; long lastDenyBot = System.currentTimeMillis() - 110000L;

  long lastLevelUp = System.currentTimeMillis() - 300000L; long nextCustom = System.currentTimeMillis() - 1000000L;

  long lastSaidLevel = System.currentTimeMillis() - 110000L; long nextModAlert = System.currentTimeMillis(); long sayNo = System.currentTimeMillis();

  int level = 0;
  boolean run = true; boolean doLevelRes = false; boolean doCustomRes = false;
  boolean typing = false;
  boolean wait = false;

  boolean pause = false;

  String[] tradeRes = { "No thanks", "No thx", "Nope", "Im fine" }; String[] greetingRes = { "hi!", "hi.", "hi", "hello", "hello!", "hello.", "hello..", "yo", "yo!", "yes?", "what", "what?", "hey!" }; String[] botterRes = { "huh", "zzz", "...", "???", "?????", "what", "what?", "no", "nop", "nope" }; String[] levelRes = { "yay", "haha", ":)", "yay!", "yay!!!", "finally..." }; String[] customDetect = new String[0]; String[] customRes = new String[0];

  double customTO = 160000.0D; double customTOR = 30000.0D;

  private WhiteBearAIOMagic$ChatResponder(WhiteBearAIOMagic paramWhiteBearAIOMagic) {
  }
  public void run() { while ((!this.this$0.thePainter.savedStats) || (getChatMessage() == null)) {
      sleepNE(200);
    }
    while (this.run)
      try {
        if ((WhiteBearAIOMagic.access$11100(this.this$0).getClientState() == 10) && (!this.pause)) {
          if ((WhiteBearAIOMagic.access$3600(this.this$0)) && (WhiteBearAIOMagic.access$11200(this.this$0)) && 
            (this.sayNo < System.currentTimeMillis())) {
            WhiteBearAIOMagic.access$11202(this.this$0, false);
            int i = this.this$0.random(110000, 130000);
            this.sayNo = (System.currentTimeMillis() + i);
            sleepNE(this.this$0.random(300, 700));
            String[] arrayOfString = this.tradeRes;
            int j = this.this$0.random(0, arrayOfString.length);
            sendText(arrayOfString[j]);
            this.this$0.log("[Response] Said No to a Trade Request. Timeout: " + i / 1000 + " sec");
          }

          String str = getChatMessage().toLowerCase();
          if ((str != null) && (!str.equals(WhiteBearAIOMagic.access$11300(this.this$0))) && (str.contains(this.this$0.getMyPlayer().getName().toLowerCase() + ": <") != true))
          {
            remoteControl(str);
            if (WhiteBearAIOMagic.access$3600(this.this$0))
              response(str);
            else {
              sleepNE(this.this$0.random(700, 850));
            }
            WhiteBearAIOMagic.access$11302(this.this$0, str);
          } else {
            sleepNE(this.this$0.random(600, 700));
          }
        } else {
          sleepNE(this.this$0.random(300, 400));
        }
      }
      catch (Throwable localThrowable)
      {
      } }

  private boolean findText(String paramString, String[] paramArrayOfString) {
    String[] arrayOfString = paramArrayOfString;
    for (int i = 0; i < arrayOfString.length; i++) {
      if (paramString.contains(arrayOfString[i])) {
        return true;
      }
    }
    return false;
  }

  private void remoteControl(String paramString) {
    if (WhiteBearAIOMagic.access$3800(this.this$0))
      try {
        String[] arrayOfString = paramString.split("</col>");
        if (arrayOfString[2].toLowerCase().contains(WhiteBearAIOMagic.access$11400(this.this$0)))
        {
          if (arrayOfString[3].toLowerCase().contains(WhiteBearAIOMagic.access$11500(this.this$0))) {
            WhiteBearAIOMagic.access$11600(this.this$0).warning("Remote Control password detected! Logging out soon.");
            String str = "/" + WhiteBearAIOMagic.access$11700(this.this$0);
            sendText(str);
            WhiteBearAIOMagic.access$11802(this.this$0, true);
          } else {
            WhiteBearAIOMagic.access$11900(this.this$0).warning("Your Remote Control Character talked to you!");
          }
        }
      }
      catch (Exception localException)
      {
      }
  }

  private void response(String paramString)
  {
    int k;
    if (this.doLevelRes) {
      if ((this.level > 0) && (WhiteBearAIOMagic.access$12000(this.this$0).getCurrentLevel(6) > this.level) && (System.currentTimeMillis() - 200000L >= this.lastLevelUp))
      {
        this.lastLevelUp = System.currentTimeMillis();
        if ((this.this$0.random(0, 11) <= 7) && (WhiteBearAIOMagic.access$12200(this.this$0).distanceTo(WhiteBearAIOMagic.access$12100(this.this$0).getNearest(Players.ALL_FILTER)) < 10))
        {
          WhiteBearAIOMagic.access$3708(this.this$0);
          sleepNE(this.this$0.random(200, 600));
          String[] arrayOfString1 = this.levelRes;
          k = this.this$0.random(0, arrayOfString1.length);
          sendText(arrayOfString1[k]);
          this.this$0.log("[Response] Level Up Response: " + arrayOfString1[k]);
          sleepNE(this.this$0.random(150, 250));
        }
        this.level = WhiteBearAIOMagic.access$12300(this.this$0).getCurrentLevel(6);
        return;
      }
      this.level = WhiteBearAIOMagic.access$12400(this.this$0).getCurrentLevel(6);
    }
    if (System.currentTimeMillis() - 150000L >= this.lastSaidLevel)
      if (findText(paramString, new String[] { "magic", "mage", "maging", "magik", "maggic" })) if (findText(paramString, new String[] { "level", "levl", "lvel", "lvl" }))
        {
          this.lastSaidLevel = System.currentTimeMillis();
          WhiteBearAIOMagic.access$3708(this.this$0);
          sleepNE(this.this$0.random(600, 2000));
          int i = this.this$0.random(1, 11);
          if (i == 1) {
            sendText("magic lvl " + WhiteBearAIOMagic.access$12500(this.this$0).getCurrentLevel(6));
          }
          else if (i == 2) {
            sendText("level: " + WhiteBearAIOMagic.access$12600(this.this$0).getCurrentLevel(6));
          }
          else if (i == 3) {
            sendText("" + WhiteBearAIOMagic.access$12700(this.this$0).getCurrentLevel(6));
          } else if (i == 4) {
            sendText("mines " + WhiteBearAIOMagic.access$12800(this.this$0).getCurrentLevel(6));
          }
          else if (i == 5) {
            sendText("lv " + WhiteBearAIOMagic.access$12900(this.this$0).getCurrentLevel(6));
          } else if (i == 6) {
            sendText(Integer.toString(WhiteBearAIOMagic.access$13000(this.this$0).getCurrentLevel(6)));
          }
          else if (i > 6) {
            sleepNE(this.this$0.random(100, 200));
            WhiteBearAIOMagic.access$13100(this.this$0).sendKey('\n');
            sleepNE(this.this$0.random(800, 1300));
            WhiteBearAIOMagic.access$13200(this.this$0).sendKey('S');
            sleepNE(this.this$0.random(800, 1300));
            WhiteBearAIOMagic.access$13300(this.this$0).sendKey('M');
            sleepNE(this.this$0.random(800, 1300));
            WhiteBearAIOMagic.access$13400(this.this$0).sendKey('2');
          }
          this.this$0.log("[Response] Answered to Level Question: '" + paramString + "'");
          sleepNE(this.this$0.random(200, 300));
          return;
        }
    String[] arrayOfString2;
    if (findText(paramString, new String[] { "bottin", "botin", "botttin", "botter", "bottter", "boter", "bootin", "boottin", "booter", "bootter" }))
    {
      if ((paramString.contains("?")) || (paramString.contains(this.this$0.getMyPlayer().getName().toLowerCase())) || (paramString.contains("!")))
      {
        if (System.currentTimeMillis() - 130000L >= this.lastDenyBot) {
          this.lastDenyBot = System.currentTimeMillis();
          WhiteBearAIOMagic.access$3708(this.this$0);
          sleepNE(this.this$0.random(600, 2000));
          arrayOfString2 = this.botterRes;
          k = this.this$0.random(0, arrayOfString2.length);
          sendText(arrayOfString2[k]);
          this.this$0.log("[Response] Answered to Botting Message: '" + paramString + "'");

          sleepNE(this.this$0.random(150, 250));
          return;
        }
      }
    }
    if (findText(paramString, new String[] { "hi ", "hello", "hi<", "hey", "hi!", "hi.", "yo!", "yo.", "yo<" }))
    {
      if (System.currentTimeMillis() - 130000L >= this.lastSaidHi) {
        this.lastSaidHi = System.currentTimeMillis();
        WhiteBearAIOMagic.access$3708(this.this$0);
        sleepNE(this.this$0.random(600, 1600));
        arrayOfString2 = this.greetingRes;
        k = this.this$0.random(0, arrayOfString2.length);
        sendText(arrayOfString2[k]);
        this.this$0.log("[Response] Answered to Greeting: '" + paramString + "'");
        sleepNE(this.this$0.random(150, 250));
        return;
      }
    }
    if ((this.doCustomRes) && (findText(paramString, this.customDetect)) && (System.currentTimeMillis() > this.nextCustom))
    {
      this.nextCustom = ()(System.currentTimeMillis() + this.this$0.random(this.customTO - this.customTOR, this.customTO + this.customTOR));

      WhiteBearAIOMagic.access$3708(this.this$0);
      sleepNE(this.this$0.random(500, 1400));
      int j = this.this$0.random(0, this.customRes.length);
      sendText(this.customRes[j]);
      this.this$0.log("[Response] Custom Response: '" + paramString + "'");
      sleepNE(this.this$0.random(150, 250));
      return;
    }
    sleepNE(this.this$0.random(650, 750));
  }

  private void sendText(String paramString) {
    char[] arrayOfChar1 = paramString.toCharArray();
    this.typing = true;
    if (this.wait) {
      for (int i = 0; i < 21; i++) {
        sleepNE(10);
        if (!this.wait) {
          i = 21;
        }
      }
    }
    for (char c : arrayOfChar1) {
      WhiteBearAIOMagic.access$13500(this.this$0).sendKey(c);
      sleepNE(this.this$0.random(280, 550));
    }
    WhiteBearAIOMagic.access$13600(this.this$0).sendKey('\n');
    this.typing = false;
  }

  private String getChatMessage() {
    try {
      String str = null;
      for (int i = 280; i >= 180; i--) {
        if ((WhiteBearAIOMagic.access$13700(this.this$0).get(137).getComponent(i).getText() == null) || 
          (!WhiteBearAIOMagic.access$13800(this.this$0).get(137).getComponent(i).getText().contains("<col=")))
          continue;
        str = WhiteBearAIOMagic.access$13900(this.this$0).get(137).getComponent(i).getText();

        break;
      }

      return str;
    } catch (Exception localException) {
    }
    return null;
  }

  private void sleepNE(int paramInt) {
    try {
      Thread.sleep(paramInt);
    }
    catch (Exception localException)
    {
    }
  }
}